package mh.message;

import java.util.ArrayList;

/**
 * This class manages each message incoming from the server.
 * 
 * @author gianmarcolaggia
 * 
 */
public class IncomingMessage {

	/**
	 * The prefix of the message (the one starting with ":")
	 */
	private String				prefix;
	/**
	 * The command of the message
	 */
	private String				command;
	/**
	 * The nickname of the player
	 */
	private String				nickname;
	/**
	 * The username of the player
	 */
	private String				username;
	/**
	 * The host of the player
	 */
	private String				host;

	/**
	 * An <code>ArrayList</code> of <code>String</code>s that contains all the params of the message.<br>
	 * All the words after the semicolon (":") are considered as one single parameter.
	 */
	private ArrayList<String>	params;

	/**
	 * Constructor. Initialize the ArrayList.
	 */
	public IncomingMessage() {
		this.params = new ArrayList<String>();
	}

	/**
	 * Method to set the <code>ArrayList</code> containing each param.
	 * 
	 * @param params
	 *            An <code>ArrayList</code> of <code>String</code>s
	 */
	public void setParams(ArrayList<String> params) {
		this.params = params;
	}

	/**
	 * Method to set the command.
	 * 
	 * @param cmd
	 *            A <code>String</code>.
	 */
	public void setCommand(String cmd) {
		this.command = cmd;
	}

	/**
	 * Method to set the prefix.
	 * 
	 * @param pr
	 *            The prefix to set.
	 */
	public void setPrefix(String pr) {
		this.prefix = pr;
	}

	/**
	 * Method used to get the command.
	 * 
	 * @return The command
	 */
	public String getCommand() {
		return this.command;
	}

	/**
	 * Method used to get the prefix.
	 * 
	 * @return The prefix
	 */
	public String getPrefix() {
		return this.prefix;
	}

	/**
	 * Method used to get the <code>ArrayList</code> of all the params.
	 * 
	 * @return The <code>ArrayList</code> containing all the params.
	 */
	public ArrayList<String> getParams() {
		return this.params;
	}

	/**
	 * Method used to set player's nickname.
	 * 
	 * @param nickname
	 *            The nickname to set
	 */
	public void setNick(String nickname) {
		if ((nickname != null) && !"".equals(nickname)) {
			this.nickname = nickname;
		}

	}

	@Override
	public String toString() {
		return this.command + " " + this.params;
	}

	public void setHost(String s) {
		this.host = s;

	}

	public void setUser(String u) {
		this.username = u;

	}
}
